package com.njtoyo.taxi.admin.mongo.repository.primary;

import com.njtoyo.taxi.admin.mongo.entity.primary.CouponMongo;
import com.njtoyo.taxi.admin.rest.presenter.finance.vo.FinanceAllowanceCouponMongoStatsVo;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.Aggregation;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.List;

public interface CouponMongoRepository extends MongoRepository<CouponMongo, ObjectId> {
    @Aggregation(pipeline = {
            "{$group: { _id: '$cantonId', count: {$sum: 1}}}"
    })
    List<FinanceAllowanceCouponMongoStatsVo> cantonCouponGrantedAll();

    @Aggregation(pipeline = {
            "{$match:{ grantedTimestamp: {$gte : ?0, $lte : ?1}}}",
            "{$group: { _id: '$cantonId', count: {$sum: 1}}}"
    })
    List<FinanceAllowanceCouponMongoStatsVo> cantonCouponGrantedWithCondition(Integer startTimeStamp, Integer endTimeStamp);
}
